<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="dao.DeviceDao" %>
<%@ page import="java.util.List" %>
<%@ page import="entity.DeviceBean" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="entity.PageBean" %>
<html>

<head>
    <meta charset="utf-8">
    <title>Bootstrap 布局实例</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/list.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/user.js"></script>
</head>

<body>

<div class="container-fluid">
    <div class="row">

        <div class="col-sm-12" id="right">
            <ol class="breadcrumb">
                <li class="active">菜单
                </li>
                <li class="active">设备信息
                </li>
            </ol>
            <%
                request.setCharacterEncoding("UTF-8");
                String name = "";
                String number = "";
                String type = "";
                String vendor = "";
                String date = "";
                if (request.getParameter("name") != null) name = request.getParameter("name");
                if (request.getParameter("number") != null) number = request.getParameter("number");
                if (request.getParameter("type") != null) type = request.getParameter("type");
                if (request.getParameter("vendor") != null) vendor = request.getParameter("vendor");
                if (request.getParameter("date") != null) date = request.getParameter("date");

                PageBean pageBean = (PageBean) request.getAttribute("pageBean");

            %>
            <div class="panel panel-default">
                <div class="panel-heading">
                    搜索
                </div>
                <div class="panel-body">
                    <form role="form" class="form-inline" action="deviceList" method="post">
                        <div class="form-group">
                            <label>设备名称</label>
                            <input type="text" class="form-control custom-smaller-input" id="name"
                                   name="name" value="<%=name%>" placeholder="请输入设备名称">
                        </div>
                        <div class="form-group">
                            <label>设备编号</label>
                            <input type="text" class="form-control custom-smaller-input" id="number"
                                   name="number" value="<%=number%>" placeholder="请输入物料名称">
                        </div>
                        <div class="form-group">
                            <label>设备类型</label>
                            <select class="form-control" name="type">
                                <option value="" <%=type.equals("") ? "selected" : "" %>>不限</option>
                                <option value="重型" <%=type.equals("重型") ? "selected" : "" %>>重型</option>
                                <option value="中型" <%=type.equals("中型") ? "selected" : "" %>>中型</option>
                                <option value="轻型" <%=type.equals("轻型") ? "selected" : "" %>>轻型</option>
                                <option value="便携式" <%=type.equals("便携式") ? "selected" : "" %>>便携式</option>
                                <option value="其它" <%=type.equals("其它") ? "selected" : "" %>>其它</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>供应商</label>
                            <input type="text" class="form-control custom-smaller-input" id="vendor"
                                   name="vendor" value="<%=vendor%>" placeholder="请输入供应商名称">
                        </div>
                        <div class="form-group">
                            <label>出厂日期</label>
                            <input type="date" class="form-control custom-smaller-input" id="date"
                                   name="date" value="<%=date%>">
                        </div>
                        <div class="form-group">
                            <button type="submit" class="searchButton btn btn-primary">搜索</button>
                        </div>
                        <div class="form-group">
                            <a class="addButton btn btn-default" href="deviceEdit?optype=add">添加</a>
                        </div>
                    </form>
                </div>
            </div>
            <!--
            列表展示
        -->
            <div class="table-responsive">
                <table class="table table-striped ">
                    <thead>
                    <tr>
                        <%--<th>序号</th>--%>
                        <th>设备名称</th>
                        <th>设备编号</th>
                        <th>设备类型</th>
                        <th>供应商名称</th>
                        <th>出厂日期</th>
                        <th>质保期</th>
                        <th>售后联系人</th>
                        <th>联系电话</th>
                        <th>质保说明</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <%
                        List<DeviceBean> deviceList = (List<DeviceBean>) request.getAttribute("list");
                        for (DeviceBean obj : deviceList) {
                    %>
                    <tr>
                        <td><%=obj.getName()%>
                        </td>
                        <td><%=obj.getNumber()%>
                        </td>
                        <td><%=obj.getType()%>
                        </td>
                        <td><%=obj.getVendor()%>
                        </td>
                        <td><%=obj.getDate()%>
                        </td>
                        <td><%=obj.getTime()%>
                        </td>
                        <td><%=obj.getAfterSales()%>
                        </td>
                        <td><%=obj.getPhone()%>
                        </td>
                        <td><%=obj.getIllustrate()%>
                        </td>
                        <td>
                            <div class="btn-group">
                                <a class="reviseButton btn btn-default" href="deviceEdit?id=<%=obj.getId()%>&optype=edit">修改</a>
                                <a class="deleteButton btn btn-danger"
                                   href="#" onclick="confirmDelete(<%=obj.getId()%>)">删除</a>
                            </div>
                        </td>
                    </tr>
                    <%
                        }
                    %>
                    </tbody>
                </table>
            </div>
            <ul class="pagination" style="float: right;">
                <li><span style="pointer-events: none">共<%=pageBean.getPageCount()%>页</span></li>
                <li>
                    <a href="deviceList?alterPage=-1&page=<%=pageBean.getCurPage()%>&name=<%=name%>&number=<%=number%>&type=<%=type%>&vendor=<%=vendor%>&date=<%=date%>">&laquo;</a>
                </li>
                <%
                    for (int i = pageBean.getStartPage() ; i <= pageBean.getEndPage(); i++) {
                        if (i == pageBean.getCurPage()) {
                            out.println("<li class=\"active\"><a href=\"deviceList?page="
                                    + i + "&name=" + name + "&number=" + number + "&type=" + type
                                    + "&vendor=" + vendor + "&date=" + date + "\">" + i + "</a></li>");
                        } else {
                            out.println("<li><a href=\"deviceList?page=" + i + "&name="
                                    + name + "&number=" + number + "&type=" + type + "&vendor=" + vendor
                                    + "&date=" + date + "\">" + i + "</a></li>");
                        }
                    }

                %>
                <li>
                    <a href="deviceList?alterPage=1&&page=<%=pageBean.getCurPage()%>&name=<%=name%>&number=<%=number%>&type=<%=type%>&vendor=<%=vendor%>&date=<%=date%>">&raquo;</a>
                </li>
            </ul>
        </div>
    </div>
</div>

</body>
<script>
    function confirmDelete(id) {
        if (confirm("确定要删除吗？")) {
            window.location.href = "deviceEdit?id="+id+"&page=<%=pageBean.getCurPage()%>&name=<%=name%>&number=<%=number%>&type=<%=type%>&vendor=<%=vendor%>&date=<%=date%>&optype=delete";
        }
    }
</script>
</html>